﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentApartMentManage
{
   
    public partial class DelStuInfo : Form
    {
        string[] recovery = new string[7];
        public DelStuInfo()
        {
            InitializeComponent();
        }
        void show(string sql)
        {
            dataGridView1.DataSource = sqlHelper.GetTable(sql);
            
        }

        private void DelStuInfo_Load(object sender, EventArgs e)
        {
            string sql0 = "select 学号,姓名,性别,学院,专业,班级,民族 from 学生信息表";
            show(sql0);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string sql0 = string.Format("select 学号,姓名,性别,学院,专业,班级,民族 from 学生信息表 where 学号='{0}'", textBox1.Text.Trim());
            dataGridView1.DataSource = sqlHelper.GetTable(sql0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < 7; i++)
                {
                    recovery[i] = dataGridView1.SelectedCells[i].Value.ToString();
                }
                string str = dataGridView1.SelectedCells[1].Value.ToString();
                if (MessageBox.Show("你真的要删除学生+" + str + "的信息吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string sql = string.Format("delete from 学生信息表 where 学号='{0}'", dataGridView1.SelectedCells[0].Value.ToString());
                    int i = sqlHelper.Execute(sql);
                    if (i != -1)
                    {
                        MessageBox.Show("删除学生信息成功!");
                        show("select 学号,姓名,性别,学院,专业,班级,民族 from 学生信息表");
                    }
                    else
                        MessageBox.Show("删除学生信息失败!");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("删除失败！");
                return;
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("你真的要撤销删除操作吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string sql = string.Format("insert into 学生信息表(学号,姓名,性别,学院,专业,班级,民族) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", recovery[0], recovery[1], recovery[2], recovery[3], recovery[4], recovery[5], recovery[6]);
                    int i = sqlHelper.Execute(sql);
                    if (i != -1)
                    {
                        MessageBox.Show("撤销删除成功!");
                        show("select 学号,姓名,性别,学院,专业,班级,民族 from 学生信息表");
                    }
                    else
                        MessageBox.Show("撤销删除失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("恢复失败!");
                return;
            }
        }
    }
}
